package packagename.states
{
	// FLASH
	import org.hive.managers.StateManager;
	import org.hive.managers.plugin.LayoutManager;
	import org.hive.sequence.*;
	import org.hive.state.*;
	
	// PROJECTNAME
	import packagename.data.*;
	import packagename.views.*;
	import packagename.states.*;
	
	public class ProjectNameHelloWorldState extends State implements IState
	{
		
		public var helloWorld	:	HelloWorldView;
		
		public override function create():ActionSequence
		{
			contentList = contentList as ProjectNameContentList;
			
				
			//________________________________________________________________________ SEQUENCE
			var createSequence:ActionSequence = new ActionSequence( String(this) + " / createSequence" );
			     
			
			helloWorld = new HelloWorldView();
			helloWorld.label_txt.text = contentList.getMessage("helloworld");
			helloWorld.alpha = 0;	
			helloWorld.x = 400;
			helloWorld.y = 200;
						
			var helloWorldTweenObj:Object = { 
								scope: helloWorld,
								time: 3,
								alpha: 1
								}
			
			createSequence.push( helloWorldTweenObj );
			
			// we add a sequence delay equal (or longer than) the longest time so that we can fire a complete event at it ends
			createSequence.push( new SequenceDelay ( 4000) ); // 4000 millisecnds = 4 seconds
			createSequence.push( new SequenceFunction (this, helloWorldComplete) );
			
			
			return createSequence;
		}
		
		private function helloWorldComplete():void
		{
				nextState();	
		}
		
		// this is a slightly different way to setup your next state  
		// we can don't need to create null instance of the next states if we're not passing in a class name
		// but again depending on a condition, we could move into different states 
						
		private function nextState():void
		{
			var nextStateSequence:ActionSequence = new ActionSequence( "Next State " );
			
			var randomNumber:Number = Math.random() * 100;
			
			if ( randomNumber > 50 ) 
			{
				nextStateSequence.push( new SequenceFunction(StateManager, StateManager.switchState, new ProjectNameBoxState() ));
			} else 
			{
				nextStateSequence.push( new SequenceFunction(StateManager, StateManager.switchState, new ProjectNameCircleState() ));
			}
			
			StateManager.playSequence(nextStateSequence);
						
		}
		
		private function kill():void
		{
			trace (String(this) + " / kill ");
						
			LayoutManager.removeChild(helloWorld);
	
		}
				
		public override function close():CloseSequence
		{
			trace (String(this) + " / close()");
			
			var closeSequence:CloseSequence = new CloseSequence( String(this) + " / CloseSequence" );
			closeSequence.push( { scope: helloWorld, alpha: 0, time: 1, scaleX: 0.25, scaleY: 0.25 } );
			closeSequence.push( new SequenceDelay( 1000 ) );
			closeSequence.push( new SequenceFunction(this, kill) );
			return closeSequence;
		}
		
	}
	
}
